﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using L2C;

namespace L2C.Controllers.Administrator
{
    [Authorize]
    public class ProductCategoryController : Controller
    {
        private L2CEntities db = new L2CEntities();

        //
        // GET: /ProductCategory/

        public ViewResult Index()
        {
            return View(db.Categories.ToList());
        }

        //
        // GET: /ProductCategory/Details/5

        public ViewResult Details(int id)
        {
            Category category = db.Categories.Single(c => c.Category_Id == id);
            return View(category);
        }

        //
        // GET: /ProductCategory/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /ProductCategory/Create

        [HttpPost]
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.AddObject(category);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(category);
        }
        
        //
        // GET: /ProductCategory/Edit/5
 
        public ActionResult Edit(int id)
        {
            Category category = db.Categories.Single(c => c.Category_Id == id);
            return View(category);
        }

        //
        // POST: /ProductCategory/Edit/5

        [HttpPost]
        public ActionResult Edit(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Attach(category);
                db.ObjectStateManager.ChangeObjectState(category, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(category);
        }

        //
        // GET: /ProductCategory/Delete/5
 
        //public ActionResult Delete(int id)
        //{
        //    Category category = db.Categories.Single(c => c.Category_Id == id);
        //    return View(category);
        //}

        //
        // POST: /ProductCategory/Delete/5

        //[HttpPost, ActionName("Delete")]
        //public ActionResult DeleteConfirmed(int id)
        //{            
        //    Category category = db.Categories.Single(c => c.Category_Id == id);
        //    db.Categories.DeleteObject(category);
        //    db.SaveChanges();
        //    return RedirectToAction("Index");
        //}

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}